package com.ktgj.customer.controller;

import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.customer.domain.PassengerDocuments;
import com.ktgj.customer.service.IPassengerDocumentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("/passengerDocuments")
public class PassengerDocumentsController {
    @Autowired
    private IPassengerDocumentsService passengerDocumentsService;

    /**
     * 根据乘车人id查询证件信息
     * */
    @PostMapping("/selectDocuments")
    public List<PassengerDocuments> selectDocumentsByCommontrvelersId(@RequestBody Map<String, Object> map) {
        Long commontrvelersId = Long.valueOf(map.get("commontrvelersId").toString());
        List<PassengerDocuments> passengerDocuments = passengerDocumentsService.selectDocumentsByCommontrvelersId(commontrvelersId);
        if (passengerDocuments.size() > 0){
            return passengerDocuments;
        }
        else {
            return null;
        }
    }

    /**
     * 后端——查询常用旅客的证件
     * @param commontrvelersId
     * @return
     */
    @PostMapping("/backSelectPassengerDocumentsBack")
    public AjaxResult backSelectPassengerDocumentsBack(@RequestParam("commontrvelersId") Long commontrvelersId) {
        return AjaxResult.success(passengerDocumentsService.backSelectPassengerDocumentsBack(commontrvelersId));
    }
}
